//
//  EFBChartsVersionSelectController.m
//  muefb
//
//  Created by 蒋 尚秀 on 12-7-16.
//  Copyright (c) 2012年 ADCC. All rights reserved.
//

#import "EFBChartsVersionViewController.h"
#import "FMDatabase.h"
#import "ChartFileHelper.h"
#import "EFBLackChartsTableViewController.h"

@interface EFBChartsVersionViewController ()

@property (nonatomic,retain) UIActivityIndicatorView *activityView;
@property (nonatomic,retain) NSMutableDictionary *lackDictionary;
@end

@implementation EFBChartsVersionViewController

@synthesize delegate;
@synthesize dataSouceArray = _dataSouceArray;
@synthesize selectedIndex = _selectedIndex;
@synthesize isExpired = _isExpired;

#define ALERT_EXPIRED 1
#define ALERT_NOT_EFFECTIVE -1
#define ALERT_SELECT_CHART  11
#define ALERT_ERROR_CHART   12
#define ALERT_INFO_CHART    13
- (id)initWithStyle:(UITableViewStyle)style{
    self = [super initWithStyle:style];
    if (self) {
    }
    
    return self;
}

-(void)dealloc
{ 
    [_dataSouceArray release];
    [_isExpired release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.currentIndex = self.selectedIndex;

    self.tableView.allowsSelection = YES;
    
    self.navigationItem.title = NSLocalizedString(@"chart-revision-choose",@"航图版本选择");
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelTaped:)] autorelease];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneTaped:)] autorelease];
    
    self.activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]autorelease];
    self.activityView.backgroundColor = [UIColor blackColor];
    self.activityView.alpha = 0.5f;
    self.activityView.frame = CGRectMake(0, 0, 540, 620);
    self.activityView.hidesWhenStopped = YES;
    [self.view addSubview:self.activityView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.isExpired = nil;
    self.dataSouceArray = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 55.0f;
}

#pragma mark UITableViewDelegate
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CGRect rect = [tableView rectForHeaderInSection:section];
    
    UIView *viewHeader = [[[UIView alloc]initWithFrame:CGRectMake( 0, 0, self.view.frame.size.width, rect.size.height)]autorelease];
//    viewHeader.backgroundColor = [UIColor colorWithRed:115/255.0 green:171/255.0 blue:251/255.0 alpha:1.000];
    
    UILabel *titleLabel = [[[UILabel alloc]initWithFrame:CGRectMake(15, 30, self.view.frame.size.width-60, 20)]autorelease];
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
    NSString *object = [self tableView:tableView titleForHeaderInSection:section];
    titleLabel.text = object;
    titleLabel.textColor = [UIColor darkGrayColor];
    titleLabel.font = [UIFont systemFontOfSize:14.0f];
    [viewHeader addSubview:titleLabel];
    
    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    deleteButton.frame = CGRectMake(CGRectGetWidth(self.view.frame)-50, 25, 50, 30);
    [deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    deleteButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
    deleteButton.tag = section;
    [deleteButton addTarget:self action:@selector(deleteChart:) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [viewHeader addSubview:deleteButton];
    
    UIButton *checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    checkButton.frame = CGRectMake(CGRectGetWidth(self.view.frame)-100, 25, 50, 30);
    [checkButton setTitle:@"检查" forState:UIControlStateNormal];
    checkButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    checkButton.tag = section;
    [checkButton addTarget:self action:@selector(checkChart:) forControlEvents:UIControlEventTouchUpInside];
    [checkButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [viewHeader addSubview:checkButton];

    deleteButton.hidden = NO;
    checkButton.hidden = NO;
    if (self.dataSouceArray.count == 1 && section == 1) {
        deleteButton.hidden = YES;
        checkButton.hidden = YES;
    }
    return viewHeader;
}

- (NSString *)pathForChartsFile:(NSString *)str
{
    NSString *folderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/charts/"];
    NSFileManager *manager=[NSFileManager defaultManager];
    if (![manager fileExistsAtPath:folderPath]) {
        [manager createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    return [folderPath stringByAppendingString:str];
}

- (void)deleteSelectChart
{
    NSInteger index = [[[NSUserDefaults standardUserDefaults] objectForKey:@"chartVersionSelect"] integerValue];
    NSDictionary *dict = self.dataSouceArray[index];
    NSMutableDictionary *dicPlist = nil;
    if ([[NSFileManager defaultManager] fileExistsAtPath:[self pathForChartsFile:@"/chartsPage.plist"]])
    {
        dicPlist = [[[NSMutableDictionary alloc] initWithContentsOfFile:[self pathForChartsFile:@"/chartsPage.plist"]] autorelease];
    }
    if (dicPlist == nil) {
        dicPlist = [NSMutableDictionary dictionary];
    }
    
    NSString *newCycleName = [dict objectForKey:@"revision_nver"];
    NSString *newFileId = dict[@"file_id"];
    
    [ChartFileHelper writeChartsLogToFile:[NSString stringWithFormat:@"航图文件%@,删除航图文件开始...",newFileId]];

    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dicPlist];
    for (NSString *s in [dicPlist allKeys]) {
        NSDictionary *d = dicPlist[s];
        NSString *fileId = d[@"file_id"];
        NSString *cycleName = d[@"cycle_name"];
        if ([newCycleName isEqualToString:cycleName] && [newFileId isEqualToString:fileId]) {
            
            [dic removeObjectForKey:s];
            [self.dataSouceArray removeObjectAtIndex:index];
            [self.isExpired removeObjectAtIndex:index];
            [[NSFileManager defaultManager] removeItemAtPath:[self pathForChartsFile:[NSString stringWithFormat:@"/%@",fileId]] error:nil];
            
            break;
        }
    }
    [dic writeToFile:[self pathForChartsFile:@"/chartsPage.plist"] atomically:YES];
    if ([dic count] == 0) {
        [[NSFileManager defaultManager] removeItemAtPath:[self pathForChartsFile:@"/chartsPage.plist"] error:nil];
    }
    
    [ChartFileHelper writeChartsLogToFile:[NSString stringWithFormat:@"航图文件%@,删除航图文件完成。剩余数据=%@",newFileId,dic]];

#warning TODO -- new changed
    if ([self.dataSouceArray count] != 0) {
        if (self.currentIndex != 0) {
            _currentIndex = 0;
            _selectedIndex = 0;
        }
        [self.tableView reloadData];
    }
    else{
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
    NSNotification* notification1 = [NSNotification notificationWithName:@"chartsDeleteReload" object:nil];
    [[NSNotificationCenter defaultCenter] postNotification:notification1];
}

- (void)deleteChart:(id)sender
{
    UIButton *button = (UIButton *)sender;
    NSString * tag = [NSString stringWithFormat:@"%ld",(long)button.tag];
    [[NSUserDefaults standardUserDefaults] setObject:tag forKey:@"chartVersionSelect"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否删除该期航图数据" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"删除", nil];
    alert.tag = ALERT_SELECT_CHART;
    [alert show];
    [alert release];
    
}

- (void)startAnimat
{
    [self.view bringSubviewToFront:self.activityView];
    [self.activityView startAnimating];
}

- (void)checkChart:(id)sender
{
    [self performSelectorOnMainThread:@selector(startAnimat) withObject:nil waitUntilDone:YES];
    UIButton *button = (UIButton *)sender;
    NSDictionary *dict = [[[NSDictionary alloc] initWithDictionary:self.dataSouceArray[button.tag]] autorelease];
    [self performSelector:@selector(tet:) withObject:dict afterDelay:0.01f];
    
//    NSSet *set = [NSSet setWithArray:dbFiles];
//    int chartsCount = [[set allObjects] count];
//    NSArray * files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:nil];
//    //（正常情况 数库读取比文件解压读取少2个,分别为 <修订单.pdf> <校核单.pdf>）
//    if ([files count] != (chartsCount + 2)) {
//        
//    }
}
- (void)tet:(NSDictionary *)dict
{
    NSString *newFileId = dict[@"file_id"];

    [ChartFileHelper writeChartsLogToFile:[NSString stringWithFormat:@"航图文件%@,开始校验航图文件。",newFileId]];

    NSString *dbPath = [self pathForChartsFile:[NSString stringWithFormat:@"/%@/tc.db3",newFileId]];
    NSMutableArray *dbFiles = [NSMutableArray array];
    if ([[NSFileManager defaultManager] fileExistsAtPath:dbPath]) {
        dbFiles = [self getChartsData:dbPath];
    }

    NSString *dataPath = [self pathForChartsFile:[NSString stringWithFormat:@"/%@/data",newFileId]];
    if (![[NSFileManager defaultManager] fileExistsAtPath:dbPath] || ![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
//#warning TODO
        [ChartFileHelper writeChartsLogToFile:[NSString stringWithFormat:@"航图文件%@,tc.db3或者data文件夹缺失",newFileId]];
        [self.activityView stopAnimating];
        [self saveData:dict status:@"1"];
        [self.tableView reloadData];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"航图数据错误，请删除后重新下载!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        alert.tag = ALERT_ERROR_CHART;
        [alert show];
        [alert release];
        return;
    }
    
    self.lackDictionary = [[[NSMutableDictionary alloc] init] autorelease];
    [dbFiles enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *file = dbFiles[idx];
        NSString *filePath = [NSString stringWithFormat:@"%@/%@",dataPath,file];
        if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
            NSString *airport = [[file componentsSeparatedByString:@"-"] firstObject];
            if ([airport isEqualToString:@"NAIP"]) {
                
            }
            if ([file hasPrefix:@"补充资料"]) {
                airport = @"补充资料";
                NSArray *tp = [file componentsSeparatedByString:@"@"];
                if ([tp count] > 1) {
                    airport = [tp objectAtIndex:1];
                }
            }
            if ([airport hasSuffix:@".PDF"]) {
                airport = @"#";
            }
            if ([airport isEqualToString:@"NAIP"]) {
                airport = @"#";
            }
            NSMutableArray *setArray = [[[NSMutableArray alloc]initWithArray:[self.lackDictionary objectForKey:airport]]autorelease];
            NSString *name = [self getChartsName:file dbPath:dbPath];
            if ([name isEqualToString:file]) {
                file = @"";
            }
            if ([name isEqualToString:@"补充资料"]) {
                name = [NSString stringWithFormat:@"%@",file];
                file = @"";
            }

            [setArray addObject:@[name,file]];
            [self.lackDictionary setObject:setArray forKey:airport];
        }
    }];

    NSString *message = @"检查完成,航图数据完整.";
    NSString *lackState = @"0";
    NSString *log = [NSString stringWithFormat:@"航图文件%@,检查完成,航图数据完整.",newFileId];
    if ([self.lackDictionary count] != 0) {
        NSArray *tp = [[self.lackDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
        NSString *object = [[[tp componentsJoinedByString:@", "] componentsSeparatedByString:@"#,"] lastObject];
        message = [NSString stringWithFormat:@"航图数据部分缺失,请根据执飞机场选择是否重新下载!\n 缺失机场:\n%@",object];
        lackState = @"1";
        log = [NSString stringWithFormat:@"航图文件%@,数据部分缺失,缺失机场:%@",newFileId,tp];
    }
    [self saveData:dict status:lackState];
    [self.tableView reloadData];
    [self.activityView stopAnimating];
    
    [ChartFileHelper writeChartsLogToFile:log];

    int tag = -1234;
    NSString *otherStr = nil;
    if (![message isEqualToString:@"检查完成,航图数据完整."]) {
        tag = ALERT_INFO_CHART;
        otherStr = @"查看详情";
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:otherStr otherButtonTitles:@"确定", nil];
    alert.tag = tag;
    [alert show];
    [alert release];
}

- (void)saveData:(NSDictionary *)dict status:(NSString *)status
{
    NSString *ver = dict[@"revision_nver"];
    NSString *fileID = dict[@"file_id"];
    
    NSMutableDictionary *dicPlist = nil;
    if ([[NSFileManager defaultManager] fileExistsAtPath:[ChartFileHelper pathForChartsPlist]])
    {
        dicPlist = [[[NSMutableDictionary alloc] initWithContentsOfFile:[ChartFileHelper pathForChartsPlist]]autorelease];
    }
    for (int i = 0; i < [dicPlist count]; i ++) {
        NSString *key = [NSString stringWithFormat:@"%d",i+1];
        NSMutableDictionary *tmp = [[[NSMutableDictionary alloc] initWithDictionary:[dicPlist objectForKey:key]]autorelease];
        if ([[tmp objectForKey:@"file_id"] isEqualToString:fileID] && [[tmp objectForKey:@"cycle_name"] isEqualToString:ver]) {
            [tmp  setObject:status forKey:@"lackStatus"];
            [dicPlist setObject:tmp forKey:key];
            [dicPlist writeToFile:[ChartFileHelper pathForChartsPlist] atomically:YES];
        }
    }
    NSInteger count = [self.dataSouceArray count];
    for (int i = 0; i < count; i ++) {
        NSMutableDictionary *dic = [self.dataSouceArray objectAtIndex:i];
        if ([[dic objectForKey:@"file_id"] isEqualToString:fileID] && [[dic objectForKey:@"revision_nver"] isEqualToString:ver]) {
            NSMutableDictionary *dict = [[[NSMutableDictionary alloc] initWithDictionary:[self.dataSouceArray objectAtIndex:i]]autorelease];
            [dict removeObjectForKey:@"lackStatus"];
            [dict setValue:status forKey:@"lackStatus"];
            [self.dataSouceArray replaceObjectAtIndex:i withObject:dict];
            break;
        }
    }
}

- (NSString *)getChartsName:(NSString *)file_name dbPath:(NSString *)dbPath
{
    __block NSString *name = file_name;
    FMDatabase* db = [FMDatabase databaseWithPath:dbPath];
    bool ret = [db openWithFlags:SQLITE_OPEN_READONLY];
    if (!ret) {
        return 0;
    }
    
    FMResultSet *results = [db executeQuery:@"select * from t_chart where file_name = ?",file_name];
    while( [results next] )
    {
        name = [[results resultDictionary] objectForKey:@"name"];
    }
    [results close];
    [db close];
    
    return name;
}
- (NSMutableArray *)getChartsData:(NSString *)dbPath
{
    NSMutableArray *array = [NSMutableArray array];
    FMDatabase* db = [FMDatabase databaseWithPath:dbPath];
    bool ret = [db openWithFlags:SQLITE_OPEN_READONLY];
    if (!ret) {
        return 0;
    }
    FMResultSet *results1 = [db executeQuery:@"select * from t_doc"];
    while( [results1 next] )
    {
        [array addObject:[results1 objectForColumnName:@"file_name"]];
    }
    [results1 close];
    
    FMResultSet *results = [db executeQuery:@"select * from t_chart"];
    while( [results next] )
    {
        [array addObject:[results objectForColumnName:@"file_name"]];
    }
    [results close];

    [db close];
    
    return array;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return NSLocalizedString(@"chart-revision-default",@"缺省版本");
    }
    else if(section == 1)
    {
        return NSLocalizedString(@"chart-revision-another",@"版本2");
    }
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.dataSouceArray.count == 2) {
        return 1;
    }
    else if(self.dataSouceArray.count == 1)
    {
        if (section == 0) {
            return 1;
        }
        else return 0;
    }
    return 0;
}

- (IBAction)cancelTaped:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - UIAlertViewDelegate 方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch(alertView.tag) {
        case ALERT_EXPIRED:
        {
            if (buttonIndex == 1) {
                self.selectedIndex = self.currentIndex;
                [delegate versionChanged:self.selectedIndex];
                [self dismissViewControllerAnimated:YES completion:nil];
            }
            break;
        }
        case ALERT_NOT_EFFECTIVE:
        {
            if (buttonIndex == 1) {
                self.selectedIndex = self.currentIndex;
                [delegate versionChanged:self.selectedIndex];
                [self dismissViewControllerAnimated:YES completion:nil];
            }
            break;
        }
        case ALERT_SELECT_CHART:
        {
            if (buttonIndex == 1) {
                [self deleteSelectChart];
            }else{
                [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"chartVersionSelect"];
            }
            break;
        }
        case ALERT_ERROR_CHART:
        {
            if (buttonIndex == 0) {
//                if (self.dissBlock) {
//                    self.dissBlock();
//                }
                [delegate chartStatusChanged];
            }
            break;
        }
        case ALERT_INFO_CHART:
        {
            if (buttonIndex == 0) {
                [self showLackChartsMessage];
            }
            [delegate chartStatusChanged];
            break;
        }
        default:
            break;
    }
}

- (IBAction)doneTaped:(id)sender {
    if (self.currentIndex != self.selectedIndex) {
        if ([[self.isExpired objectAtIndex:self.currentIndex] isEqualToValue:[NSNumber numberWithInt:1]]) {
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert-title",@"温馨提示:") message:NSLocalizedString(@"char-alert-expired", @"该版本已过期，确定要切换吗？") delegate:self cancelButtonTitle:NSLocalizedString(@"alert-cancel",@"取消") otherButtonTitles:NSLocalizedString(@"alert-sure",@"确定"), nil];
            
            alert.tag = ALERT_EXPIRED;
            [alert show];
            [alert release];
        }
        else if ([[self.isExpired objectAtIndex:self.currentIndex] isEqualToValue:[NSNumber numberWithInt:-1]]) {
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert-title",@"温馨提示:") message:NSLocalizedString(@"char-alert-not-effective", @"该版本未生效，确定要切换吗？") delegate:self cancelButtonTitle:NSLocalizedString(@"alert-cancel",@"取消") otherButtonTitles:NSLocalizedString(@"alert-sure",@"确定"), nil];
                
                alert.tag = ALERT_NOT_EFFECTIVE;
                [alert show];
                [alert release];
            }
        else{
            self.selectedIndex = self.currentIndex;
            [delegate versionChanged:self.selectedIndex];
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    }
    else
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)showLackChartsMessage
{
    EFBLackChartsTableViewController *lackChartTableVC = [[[EFBLackChartsTableViewController alloc] initWithCharts:self.lackDictionary] autorelease];
    [self.navigationController pushViewController:lackChartTableVC animated:YES];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.currentIndex = indexPath.section;
    [tableView reloadData];
}

-(NSString*)dateToString:(NSDate*)date
{
    NSDateFormatter * dateFormat = [[[NSDateFormatter alloc] init] autorelease];
    dateFormat.dateFormat =NSLocalizedString(@"formatter-type-three", @"yyyy年MM月dd日");
    NSString* dateString = [dateFormat stringFromDate:date];
    if(dateString == nil || [dateString isEqualToString:@""])
    {
        dateString = NSLocalizedString(@"updatecell-date-null",@"长期有效");
    }
    return dateString;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"DirectoryViewCell";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil) {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
	}
    if(self.currentIndex == indexPath.section)
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    if ([[self.isExpired objectAtIndex:indexPath.section] isEqualToValue:[NSNumber numberWithInt:1]]) {
        cell.textLabel.textColor = [UIColor redColor];
    }
    else if ([[self.isExpired objectAtIndex:indexPath.section] isEqualToValue:[NSNumber numberWithInt:0]]){
        cell.textLabel.textColor = [UIColor blackColor];
    }
    else
    {
        cell.textLabel.textColor =  [UIColor colorWithRed:198.0/255.0 green:135.0/255.0 blue:40.0/255.0 alpha:1];
    }
    
    NSString *status = [[self.dataSouceArray objectAtIndex:indexPath.section] objectForKey:@"lackStatus"];
    cell.imageView.image =nil;
    if ([status isEqualToString:@"1"]) {
        cell.imageView.image =[UIImage imageNamed:@"gantanhao"];
    }
    
    NSDateFormatter * dateFormat = [[[NSDateFormatter alloc] init] autorelease];
    dateFormat.dateFormat =@"yyyy-MM-dd";
    NSDate* effiectiveDate = [[self.dataSouceArray objectAtIndex:indexPath.section] objectForKey:@"effective_time"];
    NSDate* endDate = [[[NSDate alloc] initWithTimeInterval:2332800 sinceDate:effiectiveDate] autorelease];
    
    cell.textLabel.text = [NSString stringWithFormat:@"%@(%@--%@)",[[self.dataSouceArray objectAtIndex:indexPath.section]  objectForKey:@"revision_nver"],[dateFormat stringFromDate:effiectiveDate],[dateFormat stringFromDate:endDate]];
    
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@：%@  %@：%@",NSLocalizedString(@"updatecell-effective-date", @"生效日期"), [self dateToString: [[self.dataSouceArray objectAtIndex:indexPath.section] objectForKey:@"effective_time"]],NSLocalizedString(@"updatecell-expire-date", @"失效日期"),[self dateToString:[[self.dataSouceArray objectAtIndex:indexPath.section] objectForKey:@"expire_time"]]];
    
    
    
	return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
@end
